package com.example.park2301.fangke

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.lib_base.entity.FangKeBeanItem
import com.example.park2301.R
import com.example.park2301.databinding.ItemFkBinding

class FkAdapter:PagingDataAdapter<FangKeBeanItem, FkAdapter.FangViewHolder>(holl) {
    companion object{
        val holl=object :ItemCallback<FangKeBeanItem>(){
            override fun areItemsTheSame(
                oldItem: FangKeBeanItem,
                newItem: FangKeBeanItem
            ): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(
                oldItem: FangKeBeanItem,
                newItem: FangKeBeanItem
            ): Boolean {
               return oldItem.id==newItem.id
            }

        }
    }
    class FangViewHolder(view :View):ViewHolder(view){
        val binding =DataBindingUtil.bind<ItemFkBinding>(view)
    }

    override fun onBindViewHolder(holder: FangViewHolder, position: Int) {
        holder.binding?.bean=getItem(position)
        val item = getItem(position)
        holder.binding?.textView5?.apply {
            when(item?.visitStatus){
                "已通过"->{
                    setBackgroundResource(R.drawable.shape_status)
                    setTextColor(holder.itemView.context.resources.getColor(com.example.park.R.color.green))
                }
                "待审核"->{
                    setBackgroundResource(R.drawable.shape_dai)
                    setTextColor(holder.itemView.context.resources.getColor(com.example.park.R.color.org))
                }
                "已完成"->{
                    setBackgroundResource(R.drawable.shape_wancheng)
                    setTextColor(holder.itemView.context.resources.getColor(com.example.park.R.color.black))
                }
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FangViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_fk, parent, false)
        return FangViewHolder(view)
    }
}